/* 
 * Advanced Foundation Classes
 * Copyright (C) 2000/2004  Fabio Rotondo - Andrea Galimberti
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *  
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *  
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
#include <afc/easygui/easygui.h>
#include <afc/easygui/widgets.h>

int entry_activate ( DynamicClass * dc, EasyGUIContext * context, char * txt )
{
	fprintf ( stdout, "Entry Value: %s\n", txt );

	return ( 0 );
}

int btn_change ( DynamicClass * dc, EasyGUIContext * context )
{
	afc_easygui_widget_execute ( context, "entry_txt", "set_attr", AFC_EASYGUI_WIDGET_ATTR_VALUE, "hello world", AFC_EASYGUI_ARG_END );

	return ( 0 );
}

int btn_get ( DynamicClass * dc, EasyGUIContext * context )
{
	char * buf;

	afc_easygui_widget_execute ( context, "entry_txt", "get_attr", AFC_EASYGUI_WIDGET_ATTR_VALUE, & buf, AFC_EASYGUI_ARG_END );

	printf ( "Value: %s\n", buf );

	return ( 0 );

}

int main ( int argc, char * argv[] )
{
	AFC * afc = afc_new (); 
	EasyGUI * easygui = afc_easygui_new ( afc );
	int afc_res = 0;

	if ( easygui == NULL ) 
	{
	  fprintf ( stderr, "Init of class EasyGUI failed.\n" );
	  return ( 1 );
	}

	afc_easygui_init ( easygui );

	afc_easygui_set_gui ( easygui, 
		"(window TITLE=\"EasyGUI: checkbutton\" MAINWIN "
		"	(rows "
		"		(entry name=\"entry_txt\" action=\"entry_activate\" expand fill) "
		"		(cols "
		"			(button name=\"btn_change\" action=\"btn_change\" text=\"Set Text\") "
		"			(button name=\"btn_get\"    action=\"btn_get\"    text=\"Print Value\")  "
		"		)"
		"	) "
		") "
	);

	if ( ( afc_res = afc_easygui_show ( easygui ) ) != AFC_ERR_NO_ERROR ) 
	{
		fprintf ( stderr, "res: %x\n", afc_res );
	} else 
		afc_easygui_main ( easygui );

	afc_easygui_delete ( easygui );
	afc_delete ( afc );

	return ( 0 ); 
}
